<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最低提现金额（元）">
          <a-input-number  v-decorator="['minimumWithdrawal', validatorRules.minimumWithdrawal]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最高提现金额（元）">
          <a-input-number  v-decorator="['maximumWithdrawal', validatorRules.maximumWithdrawal]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="提现手续费（%）">
          <a-input-number v-decorator="[ 'withdrawal', validatorRules.withdrawal]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="不凡币充值比例为1比">
          <a-input-number  v-decorator="['remark4', validatorRules.remark4]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="领取门票有效期限（天）">
          <a-input-number v-decorator="['term', validatorRules.term]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          label="用户规则">
          <a-row :gutter="24">
            <a-col :span="24">
              <a-form-item style="min-height: 300px">
                <j-editor v-model="userRules" ></j-editor>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form-item>

        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="推广规则">
          <a-input placeholder="请输入推广规则" v-decorator="['promotionRules', validatorRules.promotionRules]" />
        </a-form-item>-->



        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          label="提现规则">
          <a-row :gutter="24">
            <a-col :span="24">
              <a-form-item style="min-height: 300px">
                <j-editor v-model="remark2" ></j-editor>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          label="客服名片">
          <j-image-upload text="上传" v-model="card" ></j-image-upload>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          label="新人有礼海报">
          <j-image-upload text="上传" v-model="newPerson" ></j-image-upload>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          label="推广图片">
          <j-image-upload text="上传" v-model="extensionPic" ></j-image-upload>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          label="玩家图片">
          <j-image-upload text="上传" v-model="playerPic" ></j-image-upload>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          label="分享海报">
          <j-image-upload text="上传" v-model="remark1" ></j-image-upload>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          :required="true"
          label="老玩家弹窗海报">
          <j-image-upload text="上传" v-model="remark3" ></j-image-upload>
        </a-form-item>

        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="0:正常,1:删除">
          <a-input placeholder="请输入0:正常,1:删除" v-decorator="['delflag', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark">
          <a-input placeholder="请输入remark" v-decorator="['remark', {}]" />
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark3">
          <a-input placeholder="请输入remark3" v-decorator="['remark3', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark4">
          <a-input placeholder="请输入remark4" v-decorator="['remark4', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark5">
          <a-input placeholder="请输入remark5" v-decorator="['remark5', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark6">
          <a-input placeholder="请输入remark6" v-decorator="['remark6', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark7">
          <a-input placeholder="请输入remark7" v-decorator="['remark7', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark8">
          <a-input placeholder="请输入remark8" v-decorator="['remark8', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark9">
          <a-input placeholder="请输入remark9" v-decorator="['remark9', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="remark10">
          <a-input placeholder="请输入remark10" v-decorator="['remark10', {}]" />
        </a-form-item>-->

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import JEditor from '@/components/jeecg/JEditor'
  import JImageUpload from '@/components/jeecg/JImageUpload'

  export default {
    name: "GRulesModal",
    components: {
      JEditor,JImageUpload
    },

    data () {
      return {
        userRules:'',
        promotionRules:'',
        remark2:'',
        card:'',
        newPerson:'',
        extensionPic:'',
        playerPic:'',
        remark1:'',
        remark3:'',
        remark4:'',
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
          minimumWithdrawal  :{rules: [{ required: true, message: '请输入最低提现金额' }]},
          maximumWithdrawal  :{rules: [{ required: true, message: '请输入最高提现金额' }]},
          withdrawal:{rules: [{ required: true, message: '请输入提现比例' }]},
          term:{rules: [{ required: true, message: '请输入领取门票有效期限' }]},
          promotionRules:{rules: [{ required: true, message: '请输入推广规则' }]},
          remark4:{rules: [{ required: true, message: '请输入不凡币比例' }]},
        },
        url: {
          add: "/grules/gRules/add",
          edit: "/grules/gRules/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.userRules = record.userRules;
        this.promotionRules = record.promotionRules;
        this.remark2 = record.remark2;

        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'minimumWithdrawal','maximumWithdrawal','withdrawal','userRules','term','promotionRules','card','newPerson','extensionPic','playerPic','delflag','remark','remark1','remark2','remark3','remark4','remark5','remark6','remark7','remark8','remark9','remark10'))
		  //时间格式化
          this.card = record.card;
          this.newPerson = record.newPerson;
          this.extensionPic = record.extensionPic;
          this.playerPic = record.playerPic;
          this.remark1 = record.remark1;
          this.remark3 = record.remark3;
          this.remark4 = record.remark4;
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        debugger
        const that = this;
        if (this.userRules == undefined || this.userRules == "") {
          this.$message.warning('请输入用户规则！')
          return false
        };
        if (this.promotionRules == undefined || this.promotionRules == '') {
          this.$message.warning('请输入推广规则！')
          return false
        };
        if (this.remark2 == undefined || this.remark2 == '') {
          this.$message.warning('请输入提现规则！')
          return false
        };
        if(this.card =="" || this.card == null){
          this.$message.warning("请上传客服名片！");
          return false;
        }
        if(this.newPerson =="" || this.newPerson == null){
          this.$message.warning("请上传客服名片！");
          return false;
        }
        if(this.extensionPic =="" || this.extensionPic == null){
          this.$message.warning("请上传推广图片！");
          return false;
        }
        if(this.playerPic =="" || this.playerPic == null){
          this.$message.warning("请上传玩家图片！");
          return false;
        }
        if(this.remark1 =="" || this.remark1 == null){
          this.$message.warning("请上传分享！");
          return false;
        }
        if(this.remark3 =="" || this.remark3 == null){
          this.$message.warning("请上传老玩家海报！");
          return false;
        }
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            formData.userRules = this.userRules;
            formData.promotionRules = this.promotionRules;
            formData.remark2 = this.remark2;
            formData.card = this.card;
            formData.newPerson = this.newPerson;
            formData.extensionPic = this.extensionPic;
            formData.playerPic = this.playerPic;
            formData.remark1 = this.remark1;
            formData.remark3 = this.remark3;
            //时间格式化

            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>